﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Drawing;


using System.Runtime.Serialization;


namespace HA.Data.DisplayOptions2
{
    [Serializable]
    public class DOVector : DataChangeProperty, IObjectDataHelper, ICloneable
    {


        //注意 ：修改字段后 需要修改运算符重载


        public DOVector()
        { 
        
        
        }


        //控制说明：如果使用不定长模式，则根据每个单元格的向量的摸乘以比例进行显示；如果使用定长模式即_isVaryLength = false，则根据长度直接进行显示，不乘以比例



        //[field: NonSerialized]
        //protected bool _isNeedUpdateData = false;


        [field: NonSerialized]
        public event EventHandler VectorsSetupChanged;


        #region 目前设计使用的字段属性


        Color _vectorColor = Color.Black;
        /// <summary>
        /// 向量颜色
        /// </summary>
        public Color VectorColor
        {
            get { return _vectorColor; }
            set
            {
                if (_vectorColor == value)
                {
                    return;
                }
                else
                {
                    _vectorColor = value;
                    this.IsNeedUpdateData = true;
                }
            }
        }




        bool _isAutoCompLength = true;
        /// <summary>
        /// 标记是否使用自动计算长度
        /// </summary>
        public bool IsAutoCompLength
        {
            get { return _isAutoCompLength; }
            set
            {
                if (_isAutoCompLength == value)
                {
                    return;
                }
                else
                {
                    _isAutoCompLength = value;
                    this.isNeedUpdateData  = true;
                }
            }
        }
        double _length = 20;
        /// <summary>
        /// 总长度（包括箭头和尾部）
        /// </summary>
        public double Length
        {
            get { return _length; }
            set
            {
                if (_length == value)
                {
                    return;
                }
                else
                {
                    _length = value;
                    this.isNeedUpdateData = true;
                }
            }
        }

        bool _isVaryLength = false;
        /// <summary>
        /// 是否使用VaryLength  ，  即使用不定长箭头模式表示
        /// </summary>
        public bool IsVaryLength
        {
            get { return _isVaryLength; }
            set
            {
                if (_isVaryLength == value)
                {
                    return;
                }
                else
                {
                    _isVaryLength = value;
                    this.isNeedUpdateData = true;
                }
            }
        }
        bool _isAutoCompScaling = true;
        /// <summary>
        /// 是否使用自动计算缩放比例
        /// </summary>
        public bool IsAutoCompScaling
        {
            get { return _isAutoCompScaling; }
            set
            {
                if (_isAutoCompScaling == value)
                {
                    return;
                }
                else
                {
                    _isAutoCompScaling = value;
                    this.isNeedUpdateData = true;
                }
            }
        }
        double _scaling = 1.0;
        /// <summary>
        /// 缩放比例
        /// </summary>
        public double Scaling
        {
            get { return _scaling; }
            set
            {
                if (_scaling == value)
                {
                    return;
                }
                else
                {
                    _scaling = value;
                    this.isNeedUpdateData = true;
                }
            }
        }


        #endregion



        #region 暂时不使用的字段属性


        double _bHeadWith = 15;
        /// <summary>
        /// 箭头头部的宽度半径（Length的百分比）
        /// </summary>
        public double BHeadWith
        {
            get { return _bHeadWith; }
            set { _bHeadWith = value; }
        }

        double _cHeadWith = 20;
        /// <summary>
        /// 箭头头部的长度（Length的百分比）
        /// </summary>
        public double CHeadWith
        {
            get { return _cHeadWith; }
            set { _cHeadWith = value; }
        }
        double _stemWith = 2;
        /// <summary>
        /// 箭头尾部的宽度半径（Length的百分比）
        /// </summary>
        public double StemWith
        {
            get { return _stemWith; }
            set { _stemWith = value; }
        }

        bool _isVaryColor = false;

        public bool IsVaryColor
        {
            get { return _isVaryColor; }
            set { _isVaryColor = value; }
        }
        bool _isDisplay = false;

        public bool IsDisplay
        {
            get { return _isDisplay; }
            set { _isDisplay = value; }
        }
        double _displayEvery = 3;

        public double DisplayEvery
        {
            get { return _displayEvery; }
            set { _displayEvery = value; }
        }
        bool _isUseEachMinAndMax = false;

        public bool IsUseEachMinAndMax
        {
            get { return _isUseEachMinAndMax; }
            set { _isUseEachMinAndMax = value; }
        }
        bool _isColorSpecified = false;

        public bool IsColorSpecified
        {
            get { return _isColorSpecified; }
            set { _isColorSpecified = value; }
        }
        double _minMagnitude;

        public double MinMagnitude
        {
            get { return _minMagnitude; }
            set { _minMagnitude = value; }
        }
        double _maxMagnitude = 1;

        public double MaxMagnitude
        {
            get { return _maxMagnitude; }
            set { _maxMagnitude = value; }
        }


        #endregion


        public object Clone()
        {
            DOVector obj = (DOVector)this.MemberwiseClone();
           
            obj._vectorColor = System.Drawing.Color.FromArgb(_vectorColor.A, _vectorColor.R, _vectorColor.G, _vectorColor.B);

            return obj;

            //return this.MemberwiseClone();
        }



        //public void ResetVecorOption(DOVector vector)
        //{
        //    this._bHeadWith = vector._bHeadWith;
        //    this._cHeadWith = vector._cHeadWith;
        //    this._displayEvery = vector._displayEvery;
        //    this._isAutoCompLength = vector._isAutoCompLength;
        //    this._isAutoCompScaling = vector._isAutoCompScaling;
        //    this._isColorSpecified = vector._isColorSpecified;
        //    this._isDisplay = vector._isDisplay;
        //    this._isUseEachMinAndMax = vector._isUseEachMinAndMax;
        //    this._isVaryColor = vector._isVaryColor;
        //    this._isVaryLength = vector._isVaryLength;
        //    this._length = vector._length;
        //    this._maxMagnitude = vector._maxMagnitude;
        //    this._minMagnitude = vector._minMagnitude;
        //    this._scaling = vector._scaling;
        //    this._stemWith = vector._stemWith;


        //    if (VectorsSetupChanged != null)
        //    {
        //        this.VectorsSetupChanged(this, new EventArgs());
        //    }
            
        //    //触发事件


        //}


        //public bool IsDataValueChanged( )
        //{


        //    return true;
        //}









        #region IObjectDataHelper 成员

        public void ResetDataAndTriggerEvent(object obj)
        {

            //需要具体实现


            if (obj == null)
            {
                return;
            }
            DOVector vector = (DOVector)obj;

            //运算符重载   其根本还是遍历类中的所有字段进行了比较  
            if (vector.IsDataChanged() == false)
            {
                return;
            }


            //if (this != vector)
            {

                //赋值部分不应该包括单独走事件更新的数据部分

                List<string> vectorStr = new List<string>();

                if (this._vectorColor .R !=vector._vectorColor .R ||this._vectorColor .G!=vector ._vectorColor .G ||this._vectorColor .B !=vector ._vectorColor .B ||this._vectorColor .A !=vector ._vectorColor .A )
                {
                    this._vectorColor = System.Drawing.Color.FromArgb(vector._vectorColor.A,vector ._vectorColor .R,vector._vectorColor.G,vector._vectorColor .B);
                    vectorStr.Add("vectorStr");

                }
                if (_bHeadWith != vector._bHeadWith)
                {
                    this._bHeadWith = vector._bHeadWith;
                    vectorStr.Add("vectorStr");

                }
                if (_cHeadWith != vector._cHeadWith)
                {
                    this._cHeadWith = vector._cHeadWith;
                    vectorStr.Add("vectorStr");
                }
                if (_displayEvery != vector._displayEvery)
                {
                    this._displayEvery = vector._displayEvery;
                    vectorStr.Add("vectorStr");
                }
                if (_isAutoCompLength != vector._isAutoCompLength)
                {
                    this._isAutoCompLength = vector._isAutoCompLength;
                    vectorStr.Add("vectorStr");
                }
                if (_isAutoCompScaling != vector._isAutoCompScaling)
                {
                    this._isAutoCompScaling = vector._isAutoCompScaling;
                    vectorStr.Add("vectorStr");
                }
                if (_isColorSpecified != vector._isColorSpecified)
                {
                    this._isColorSpecified = vector._isColorSpecified;
                    vectorStr.Add("vectorStr");
                }
                if (_isDisplay != vector._isDisplay)
                {
                    this._isDisplay = vector._isDisplay;
                    vectorStr.Add("vectorStr");
                }
                if (_isUseEachMinAndMax != vector._isUseEachMinAndMax)
                {
                    this._isUseEachMinAndMax = vector._isUseEachMinAndMax;
                    vectorStr.Add("vectorStr");
                }
                if (_isVaryColor != vector._isVaryColor)
                {
                    this._isVaryColor = vector._isVaryColor;
                    vectorStr.Add("vectorStr");
                }
                if (_isVaryLength != vector._isVaryLength)
                {
                    this._isVaryLength = vector._isVaryLength;
                    vectorStr.Add("vectorStr");
                }
                if (_length != vector._length)
                {
                    this._length = vector._length;
                    vectorStr.Add("vectorStr");
                }
                if (_maxMagnitude != vector._maxMagnitude)
                {
                    this._maxMagnitude = vector._maxMagnitude;
                    vectorStr.Add("vectorStr");
                }
                if (_minMagnitude != vector._minMagnitude)
                {
                    this._minMagnitude = vector._minMagnitude;
                    vectorStr.Add("vectorStr");
                }
                if (_scaling != vector._scaling)
                {
                    this._scaling = vector._scaling;
                    vectorStr.Add("vectorStr");
                }
                if (_stemWith != vector._stemWith)
                {
                    this._stemWith = vector._stemWith;
                    vectorStr.Add("vectorStr");
                }


                if (vectorStr.Count > 0)
                {
                    vectorStr.Clear();
                    if (VectorsSetupChanged != null)
                    {
                        this.VectorsSetupChanged(this, new EventArgs());
                    }

                }




            }






            //throw new NotImplementedException();
        }
 
        public bool IsDataChanged()
        {
            if (this.isNeedUpdateData == true)
            {
                return true;
            }
            else
            {
                return false;      
            }


            //throw new NotImplementedException();
        }


        #endregion


        [OnDeserializing]
        public void OnDeserializing(StreamingContext context)
        {
            if (this.VectorColor  == null)
            {
                this.VectorColor = System.Drawing.Color.Black;
            }

            

        }


        #region 运算符重写

        //public static bool operator ==(DOVector sp1, DOVector sp2)
        //{
        //    // check for both null (cast to object or recursive loop)
        //    if ((object)sp1 == null && (object)sp2 == null)
        //    {
        //        return true;
        //    }

        //    // check for either of them == to null
        //    if ((object)sp1 == null || (object)sp2 == null)
        //    {
        //        return false;
        //    }

        //    if (sp1._colorMode == sp2._colorMode)
        //    {
        //        return false;
        //    }
        //    if (sp1._contourColors == sp2._contourColors)
        //    {
        //        return false;
        //    }
        //    if (sp1._contourDisplayType == sp2._contourDisplayType)
        //    {
        //        return false;
        //    }
        //    if (sp1._contourInterval == sp2._contourInterval)
        //    {
        //        return false;
        //    }
        //    if (sp1._contourlines == sp2._contourlines)
        //    {
        //        return false;
        //    }
        //    if (sp1._dsMax == sp2._dsMax)
        //    {
        //        return false;
        //    }
        //    if (sp1._dsMin == sp2._dsMin)
        //    {
        //        return false;
        //    }
        //    if (sp1._isShowLegend == sp2._isShowLegend)
        //    {
        //        return false;
        //    }
        //    if (sp1._isSpecifyPrecision == sp2._isSpecifyPrecision)
        //    {
        //        return false;
        //    }
        //    if (sp1._isSpecifyRange == sp2._isSpecifyRange)
        //    {
        //        return false;
        //    }
        //    if (sp1._precision == sp2._precision)
        //    {
        //        return false;
        //    }
        //    if (sp1._spRangeMax == sp2._spRangeMax)
        //    {
        //        return false;
        //    }
        //    if (sp1._spRangeMin == sp2._spRangeMin)
        //    {
        //        return false;
        //    }
        //    if (sp1._transparency == sp2._transparency)
        //    {
        //        return false;
        //    }


        //    return true;

        //}


        //public static bool operator !=(DOContourOptionV2 sp1, DOContourOptionV2 sp2)
        //{
        //    return (!(sp1 == sp2));

        //}


        #endregion



    }
}
